package com.appkubes.mall.admin.application.goods.specific.service.impl;

import com.appkubes.mall.admin.application.goods.goods.dao.GoodsSpecificSkuDao;
import com.appkubes.mall.admin.application.goods.specific.entity.vo.GoodsSkuSearchVO;
import com.appkubes.mall.admin.application.goods.specific.service.GoodsSpecificSkuService;
import com.appkubes.mall.core.entity.MallGoodsSpecificSku;
import com.appkubes.mall.core.service.impl.BaseMallGoodsSpecificSkuServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsSpecificSkuServiceImpl extends BaseMallGoodsSpecificSkuServiceImpl implements GoodsSpecificSkuService {

    @Resource
    GoodsSpecificSkuDao goodsSpecificSkuDao;


    public GoodsSpecificSkuDao getDao() {
        return goodsSpecificSkuDao;
    }

    @Override
    public List<String> getSkuCodes(String goodsKey) {
        List<String> arr = new ArrayList<>();
        MallGoodsSpecificSku searchEntity = new MallGoodsSpecificSku();
        searchEntity.setGoodsKey(goodsKey);
        List<MallGoodsSpecificSku> mallGoodsSpecificSkuList = this.selectListByEntity(searchEntity);
        if (mallGoodsSpecificSkuList.size() == 0) return  null;
        for (MallGoodsSpecificSku mallGoodsSpecificSku : mallGoodsSpecificSkuList) {
            arr.add(mallGoodsSpecificSku.getSkuCode());
        }
        return arr;
    }

    @Override
    public int setDefaultFalse(String goodsKey, String skuDims, String skuCode) {
        MallGoodsSpecificSku mallGoodsSpecificSku = new MallGoodsSpecificSku();
        mallGoodsSpecificSku.setIsDefault(0);
        QueryWrapper<MallGoodsSpecificSku> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("goods_key", goodsKey);
        queryWrapper.ne("sku_code", skuCode);
        queryWrapper.eq("sku_dims", skuDims);
        return this.update(mallGoodsSpecificSku, queryWrapper)?1:0;
    }

    @Override
    public List<MallGoodsSpecificSku> search(GoodsSkuSearchVO goodsSkuSearchVO) {
        MallGoodsSpecificSku mallGoodsSpecificSku = new MallGoodsSpecificSku();
        mallGoodsSpecificSku.setGoodsKey(goodsSkuSearchVO.getGoodsKey());
        mallGoodsSpecificSku.setSkuDims(goodsSkuSearchVO.getSkuDims());
        return selectListByEntity(mallGoodsSpecificSku);
    }

}
